package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.CautionMapper;
import com.ayou.eggguard.farm.pojo.Caution;
import com.ayou.eggguard.farm.service.CautionService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CautionServiceImpl implements CautionService {
    @Autowired
    private CautionMapper cautionMapper;

    @Override
    public PageBean<Caution> getCautionList(Integer pageNum, Integer pageSize, LocalDateTime startTime,LocalDateTime endTime, String cautionType, String cautionStatus, String coopNumber) {
        PageBean<Caution> pb=new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<Caution> list=cautionMapper.getCautionList(startTime,endTime,cautionType,cautionStatus,coopNumber);
        Page<Caution> p= (Page<Caution>) list;
        pb.setItems(p.getResult());
        pb.setTotal(p.getTotal());
        return pb;
    }

    @Override
    public void updateCautionStatus(Integer id) {
        cautionMapper.updateCautionStatus(id);
    }

    @Override
    public List<Map<String, Object>> getCautionTypeCount() {
        return cautionMapper.getCautionTypeCount();
    }

    @Override
    public List<Map<String, Object>> getCautionCount() {
        return cautionMapper.getCautionCount();
    }

}
